<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
	<title><spring:message code="title.app"/></title>
	<link rel="stylesheet" type="text/css" href="<c:url value="/static/css/lender.css" />"/>
	<link rel="stylesheet" type="text/css" href="<c:url value="/static/css/jquery.datetimepicker.css" />"/>
	<script type="text/javascript" src="<c:url value="/static/js/vendor/jquery-1.10.2.js" />" ></script>
	<script type="text/javascript" src="<c:url value="/static/js/vendor/jquery.datetimepicker.js" />" ></script>
	<script type="text/javascript" src="<c:url value="/static/js/lender.js" />"></script>
</head>
<body>

	<h2><spring:message code="title.app"/></h2>

<%-- 	<c:choose> --%>
<%-- 		<c:when test="${loan.extendedCount == 0}"> --%>
			<form:form method="post" action="history.html" commandName="client">
		
				<table>
					<tr>
						<td><form:label path="email">
								<spring:message code="label.email" />
							</form:label></td>
						<td><form:input path="email" /></td>
					</tr>
					<tr>
						<td colspan="2"><input type="submit" value="<spring:message code="label.history"/>" />
						<a href="loans"><spring:message code="label.applyloan" /></a>
					</td>
					</tr>
				</table>
			</form:form>
<%-- 		</c:when> --%>
<%-- 		<c:otherwise> --%>
<%-- 			<td><spring:message code="cannot.find.client"/></td> --%>
<%-- 		</c:otherwise>	 --%>
<%-- 	</c:choose> --%>

	<c:if test="${!empty email}">
		<h3>Loan History of ${firstname} ${lastname}</h3>
	</c:if>
	<c:if test="${!empty loanList}">
		<table class="data">
			<tr>
				<th>Reference ID</th>
				<th>Amount</th>
				<th>Term</th>
				<th>Extended?</th>
				<th>&nbsp;</th>
			</tr>
			<c:forEach items="${loanList}" var="loan">
				<tr>
					<td>${loan.referenceId}</td>
					<td>${loan.amount}</td>
					<td>${loan.term}</td>
					
					<c:choose>
						<c:when test="${loan.extendedCount == 0}">
							<td>Not extended yet</td>
						</c:when>
						<c:otherwise>
							<td>${loan.extendedCount} ${loan.extendedCount > 1 ? 'weeks' : 'week' } extended</td>
						</c:otherwise>
					</c:choose>
					
					<td><a href="extend/${loan.referenceId}">extend</a></td>
				</tr>
			</c:forEach>
		</table>
	</c:if>


</body>
</html>
